1
Choose the Rows to Keep
DSAI2202Lab 7: Reasoning Across Relationships

UniLearn's registry and LMS do not contain the same student IDs. The team needs several reports, each with a different answer to “Which source rows must appear?”

Reuse the Lab 6 Database

If you already ran lab6_7_setup.sql in Lab 6, keep that data. Otherwise, open the shared setup file supplied by your tutor in pgAdmin and run it once. Select lab6_7 in every new Query Tool connection.

Begin with the Join You Know

  1. Inspect students and lms_roster: 22 registry IDs and 6 LMS IDs.
  2. Run the INNER JOIN from Lab 6's matching rule.
  3. Identify the four IDs in both sources.
  4. Explain why this result cannot be a complete list from either source.

Five Report Requests

List shared accounts; keep every registry student; keep every LMS account; reconcile both sources; generate student–course options. You will write INNER, LEFT, RIGHT, FULL and CROSS JOIN queries for these requests.

✍️ Predict the Missing Context
S103 is registered but has no LMS account. S901 is imported into the LMS but is absent from the registry. Where would each belong in a complete report?
Shared accounts
SET search_path TO lab6_7;

SELECT s.student_id AS registry_id, s.student_name,
       r.student_id AS lms_id, r.lms_name
FROM students AS s
INNER JOIN lms_roster AS r
  ON s.student_id = r.student_id
ORDER BY s.student_id;
Check the matched IDs

Four rows: S101, S102, S105 and S121. Each ID is unique in both tables, so each matched pair appears once. This report contains only shared accounts.

Uma (S121) has an LMS account even though she has no enrolments. An account match does not prove course participation.